//
//  NavigationViewController.m
//  map
//
//  Created by dllo on 16/4/22.
//  Copyright © 2016年 王彦森. All rights reserved.
//

#import "NavigationViewController.h"
#import <AMapNaviKit/AMapNaviManager.h>//导航管理类
#import <AMapNaviKit/AMapNaviServices.h>
#import <AMapNaviKit/MAPointAnnotation.h>
#import "NavPointAnnotation.h"
#import <AMapNaviKit/AMapNaviRoute.h>
#import <AMapNaviKit/MAMapKit.h>

#define kSetingViewHeight   150.f
typedef NS_ENUM(NSInteger, NavigationTypes)
{
    NavigationTypeNone = 0,
    NavigationTypeSimulator, // 模拟导航
    NavigationTypeGPS,       // 实时导航
};

typedef NS_ENUM(NSInteger, TravelTypes)
{
    TravelTypeCar = 0,      // 驾车方式
    TravelTypeWalk,         // 步行方式
};



@interface NavigationViewController ()<AMapNaviManagerDelegate,MAMapViewDelegate>
@property(nonatomic,strong)AMapNaviManager *naviManager;
@property(nonatomic,strong)UITextField *startText;
@property(nonatomic,strong)UITextField *endText;
@property(nonatomic,strong)AMapNaviPoint *startPoint; //起点坐标
@property(nonatomic,strong)AMapNaviPoint *endPoint; //终点坐标

@property(nonatomic)BOOL calRouteSuccess; // 指示是否算路成功
@property(nonatomic,strong)MAMapView *mapView;

@property (nonatomic) NavigationTypes naviType;
@property (nonatomic) TravelTypes travelType;
@end

@implementation NavigationViewController
- (void)initNaviManager
{
    if (self.naviManager == nil) {
        self.naviManager = [[AMapNaviManager alloc]init];
        [self.naviManager setDelegate:self];
    }
}






- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
[AMapNaviServices sharedServices].apiKey = @"08311feb492c0460ac506596b7fadbc1";
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 230)];
    backView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:backView];
    
    
    UISegmentedControl *seg =[[UISegmentedControl alloc]initWithItems:@[@"步行",@"驾车"]];
    seg.frame =CGRectMake(150, 10, 100, 30);
    [seg addTarget:seg action:@selector(seg:) forControlEvents:UIControlEventEditingChanged];
    seg.backgroundColor =[UIColor yellowColor];
    seg.tintColor = [UIColor redColor];
    seg.selectedSegmentIndex = 0;
    [self.view addSubview:seg];
    
    
    self.startText = [[UITextField alloc]initWithFrame:CGRectMake(0, 40, 200, 50)];
    self.startText.placeholder = @"我的位置";
    self.startText.textColor = [UIColor grayColor];
    [self.view addSubview:self.startText];
    
    self.endText = [[UITextField alloc]initWithFrame:CGRectMake(0, 120, 200, 50)];
    self.endText.placeholder = @"终点站";
    [self.view addSubview:self.endText];
    
    UIButton *routeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [routeBtn setTitle:@"路径规划" forState:UIControlStateNormal];
    [routeBtn addTarget:self action:@selector(routeCal:) forControlEvents:UIControlEventTouchUpInside];
    routeBtn.frame =CGRectMake(80, 180, 100, 40);
    [self.view addSubview:routeBtn];
    
    
    UIButton *gpsBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [gpsBtn setTitle:@"实时导航" forState:UIControlStateNormal];
//    [gpsBtn addTarget:self action:@selector(gpsNavi:) forControlEvents:UIControlEventTouchUpInside];
    gpsBtn.frame =CGRectMake(220, 180, 100, 40);
    [self.view addSubview:gpsBtn];

    [MAMapServices sharedServices].apiKey = @"be1925d505bdc43b003a0d9909f29a5b";
    self.mapView = [[MAMapView alloc]initWithFrame:CGRectMake(0, 230, self.view.frame.size.width, self.view.frame.size.height-230)];
    self.mapView.delegate =self;
    [self.view addSubview:_mapView];

}

#pragma mark 路径查询
-(void)routeCal:(UIButton*)but{
   

}

#pragma mark seg的点击方法
-(void)seg:(UISegmentedControl*)seg{


}

#pragma mark 导航路径信息
- (void)showRouteWithNaviRoute:(AMapNaviRoute *)naviRoute
{
    
    NSLog(@"ddddddd");
    


}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.startText resignFirstResponder];
    [self.endText resignFirstResponder];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
